package com.jacklin.account.controller;

import com.jacklin.account.domain.Account;
import com.jacklin.account.service.AccountService;
import org.jacklin.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @describe: AccountController
 * @author: jacklin
 * @date: 2022-03-28 22:17
 */
@RestController
@RequestMapping(value = "/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    /**
     * 扣减账户余额
     */
    @RequestMapping("/decrease")
    public Result decrease(@RequestParam("userId") Integer userId, @RequestParam(value = "accountId") Integer accountId, @RequestParam("money") BigDecimal money) {
        accountService.decrease(userId, accountId, money);
        return Result.OK("扣减账户余额成功");
    }

    /**
     * @describe: 根据id查询账户信息
     * @author: jacklin
     * @date: 2022/3/28
     **/
    @GetMapping(value = "/getById")
    public Result<?> getById(@RequestParam String id) {
        return Result.OK(accountService.getById(id));
    }

    /**
     * @describe: 更新账户信息
     * @author: jacklin
     * @date: 2022/3/28
     **/
    @PostMapping(value = "/updateById")
    public Result<?> updateById(@RequestBody Account account) {
        return Result.OK(accountService.updateById(account));
    }
}
